<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>JS原型</h2>
</body>
<script>
    //类，对一类相似事物描述
    function Person(name='无名',age=0) {
        this.name=name;
        this.age=age;
    }

    //相似的功能也称方法,通过原型来描述
    Person.prototype.play=function() {
        console.log(`${this.name}喜欢的游戏`)
    }

//     Object.prototype.play=function() {
//       console.log(`${this.name}喜欢的游戏`)
//    }

    //实例化对象
    const p1=new Person('张三',20)
    const p2=new Person('李四',21)

    // p1.play=function() {
    //     console.log(`${p1.name}喜欢运动`)
    // }
    // delete p1.play
  //  p1.play()
    // p2.play()

    // console.log(p1.__proto__===Person.prototype)
    // console.log(Person.prototype.__proto__===Object.prototype)
    // console.log(Object.prototype.__proto__===null)
    //console.log(Person.prototype.constructor)
    console.log(p1.constructor)

</script>
</html>